<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\user_center\model\user;

use think\Model;

/**
 * 用户黑名单列表 模型
 * @package app\user_center\model
 */
class UcMemberBlackList extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_uc_member_blacklist';
	
	/**
     * 拉黑用户
     * @param int $uid     		用户id
     * @param int $black_uid    拉黑用户的id
     * @author shiqiang <976162041@qq.com>
     * @return array
     */
	public function addData($uid, $black_uid){
		$this->uid			= $uid;
		$this->black_uid	= $black_uid;
        $res = $this -> isUpdate(false) -> save();//添加  thinkphp主键bug
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
	}
	
	/*
	 * 取消拉黑
	 */
	public function deleteData($uid, $black_uid){
		$data = [];
		$data['uid'] = $uid;
		$data['black_uid'] = $black_uid;
		$res = $this -> destroy($data);
		if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
	}
	
	/*
	 * 查询信息
	 */
	public function getDataByUid($uid){
		$map = [];
		$map['uid'] = $uid;
		$res = $this -> where($map) -> order('create_time desc') -> paginate();
		
		if($res){
            return array_out(200, 'success', $res);
        }else{
            return array_out(-1001, 'error');
        }
	}
	
	/**
     * 用户统计 关联载入（一对一）
     */
    public function getUcMember(){
        return $this -> hasOne('app\user_center\model\user\Member','uid', 'uid');
    }
	
	public function getUcMemberBlackUid(){
        return $this -> hasOne('app\user_center\model\user\Member','uid', 'black_uid');
    }
}
